package dq.study.jvm.classloader;

/**
 * 类初始化和实例化顺序
 *
 *
 * <p>
 *     <clinit>
 *         st = new StaticTest()
 *         <init>
 *               System.out.println("2");
 *               System.out.println("3");
 *               System.out.println("a=" + a + ",b=" + b);
 *         </init>
 *         System.out.println("1");
 *         b = 112;
 *     </clinit>
 * </p>
 *
 * @author dongqun
 * @date 2020/9/8 11:03
 */
public class InitializedInstantiationSequence {
    public static void main(String[] args) {
        staticFunction();
    }

    static InitializedInstantiationSequence st = new InitializedInstantiationSequence();

    static {   //静态代码块
        System.out.println("1");
    }

    {       // 实例代码块
        System.out.println("2");
    }

    InitializedInstantiationSequence() {    // 实例构造器
        System.out.println("3");
        System.out.println("a=" + a + ",b=" + b);
    }

    public static void staticFunction() {   // 静态方法
        System.out.println("4");
    }

    int a = 110;    // 实例变量
    static int b = 112;     // 静态变量
    static InitializedInstantiationSequence st1 = new InitializedInstantiationSequence();
}

// 2
// 3
// a=110,b=0
// 1
// 2
// 3
// a=110,b=112
// 1
// 4